package org.example.hotel.controller;

import org.example.hotel.dto.WindRequest;
import org.example.hotel.entity.Room;
import org.example.hotel.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//访问：http://localhost:8088/api/ac/serving-rooms
//访问：http://localhost:8088/api/ac/waiting-rooms
@RestController
@RequestMapping("/api/ac")
public class ScheduleController {

    @Autowired
    private ScheduleService acService;

    @GetMapping("/serving-rooms")
    public List<Room> getServingRooms() {
        return acService.getCurrentServingRooms();
    }

    @GetMapping("/waiting-rooms")
    public List<Room> getWaitingRooms() {
        return acService.getCurrentWaitingRooms();
    }

    @PostMapping("/wind-request")
    public String handleWindRequest(@RequestBody WindRequest request) {
        int roomId = request.getRoomId();
        Room.WindSpeed speedEnum;
        try {
            speedEnum = Room.WindSpeed.valueOf(String.valueOf(request.getWindSpeed()));
        } catch (IllegalArgumentException e) {
            return "无效的风速：" + request.getWindSpeed();
        }

        acService.processWindRequest(roomId, speedEnum);

        return "请求已受理，当前风速：" + speedEnum.name();
    }
}